//
//  OCSSHomeTableHeaderView.swift
//  OCSSStoreSwift
//
//  Created by MacMiniKangChe on 2018/10/12.
//  Copyright © 2018年 MacMiniKangChe. All rights reserved.
//

import UIKit
import SwiftyJSON

class OCSSHomeTableHeaderView: OCSSBaseView {
    
    @IBOutlet weak var dateBtn: UIButton!
    @IBOutlet weak var totalIncome: UILabel!
    @IBOutlet weak var totalOrders: UILabel!
    @IBOutlet weak var onlineOrders: UILabel!
    @IBOutlet weak var offlineOrders: UILabel!
    @IBOutlet weak var bottomView: UIView!
    
    var paraVC:OCSSHomePage?;
    var headerInfo:[String:String]? = nil{
        didSet{
            let income = headerInfo?["SalesRevenue"]! as! NSString;
            totalIncome.text = String(format: "%.2f", income.floatValue/10000);
            totalOrders.text = headerInfo?["SalesOrder"];
            onlineOrders.text = headerInfo?["OnlineOrder"];
            offlineOrders.text = headerInfo?["Offline"];
        }
    };
    
    
    override func awakeFromNib() {
        super.awakeFromNib();
        self.bottomView.frame.size = CGSize.init(width: 414, height: 14);
        self.bottomView.anyDirectCorner(radius: 14);
    }
    @IBAction func timeButtonEvent(_ sender: UIButton) {
        let actionSheet = UIAlertController.init(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet);
        let selectDate:[NSDictionary] = [["name":"今日","id":"JinRi"],               ["name":"一周","id":"Zhou"],["name":"一月","id":"Yue"],["name":"一年","id":"Nian"]];
        let cancelAction = UIAlertAction.init(title: "取消", style: UIAlertActionStyle.cancel, handler: nil);
        actionSheet.addAction(cancelAction);
        for date in selectDate {
            let action = UIAlertAction.init(title: date["name"] as? String, style: UIAlertActionStyle.default) { (alertView:UIAlertAction) in
                self.dateBtn.setTitle(date["name"] as? String, for: UIControlState.normal);
                NotificationCenter.default.post(name: NSNotification.Name("DateSelectNotifacation"), object: date["id"]);
            }
            actionSheet.addAction(action);
        }
        paraVC?.present(actionSheet, animated: true, completion: nil);
    }
//    MARK:
    
}
